<?php
include('../conn.php');
require('../../tool/UploadImage.class.php');

// 需传参数 
$id=$_REQUEST['id'];
$user_comment = $_REQUEST['user_comment'];
$user_images = $_FILES['user_images'];
// 需传参数 end

// 状态
$state1 = 1;
$state4 = 4;
// 状态 end

if ($id != '') {

	// 查询订单id 
	$query = mysql_query("select ordersid from tuihuo where id=".$id);
	$tuihuo = mysql_fetch_assoc($query);
	$ordersid = $tuihuo['ordersid'];
	// 查询订单id end

	// 上传照片
	if ($user_images['name'][0] != '') {
		$upload = new Upload("user_images");
		$date = date('Y-m-d');
		$sumbimage = '../../sumbimage/'.$date;
		$srcimage = '../../srcimage/'.$date;
		$upload->setFilePath($srcimage);
		$upload->setSmallFilePath($sumbimage);
		$re = $upload->upload();
		if($re){
			$path = $upload->getPath();
			$smallPath = $upload->getSmallimg();
			
			foreach ($path as $key => $value) {
				$path[$key] = 'srcimage/'.$date.'/'.$value;
				$smallPath[$key] = 'sumbimage/'.$date.'/'.$smallPath[$key];
			}
		
			$user_srcimages = implode(',',$path);
			$user_images = implode(',',$smallPath);
		}
		
		// $UpFileTool=new UpFileTool('user_images');
		// $UpFileTool->multiImage($w=500, $h=500 ,$sumbimage='../../sumbimage', $srcimage='../../srcimage');
		// $user_images = $UpFileTool->multiSumbImage;
		// $user_srcimages = $UpFileTool->multiSrcImage;
		$query = mysql_query("UPDATE tuihuo set user_images='".$user_images."',user_srcimages='".$user_srcimages."' where id=".$id);
	}
	// 上传照片 end

	$query = mysql_query("UPDATE tuihuo set state='".$state1."',user_comment='".$user_comment."' where id=".$id);

	if (mysql_affected_rows()>0) {
		$arr = array('code' => 200, 'msg' => '申请成功', 'id' => $id);
	}else{
		$arr = array('code' => 201, 'msg' => '未更改数据');
	}

	// 调用信息推送接口
	$url = "http://120.24.0.10/xzpf/api/jpush/jpush.php?state=".$state4."&ordersid=".$ordersid;
	file_get_contents($url);
	// 调用信息推送接口 end


}else{
	$arr = array('code' => 400, 'msg' => 'id不存在,可传参数：user_images,user_comment');
}

echo json_encode($arr);


